使用Wiremock检查请求正文中的空值 | 您所在的位置:网站首页 › measure用法 值 › 使用Wiremock检查请求正文中的空值 |
在WireMock documentation on Request Matching中有关JSON Path matching的部分。在source code中有一个对使用的com.jayway.jsonpath.JsonPath库的引用。build.gradle指的是版本2.4.0。Jayway JSON Path库的文档可以在他们的Github project page上找到。有一个很好的,但绝不是完美的在线评估器here。 WireMock文档仅显示对"matchesJsonPath“形式的节点值的正则表达式的支持。在Jayway文档中有一个在线示例:[$..book?(@.author =~ /.*REES/i)](http://jsonpath.herokuapp.com/?path=$..book[?(@.author%20=~%20/.*REES/i%29])。因此,惟一的方法是命名所有不允许为null的节点。 在下面的示例中,将测试所有提到的节点映射,而不考虑它们的深度(请参阅@id)。如果所有提到的节点都不是空的,但一些未提到的节点是空的,则不会触发此映射。 { "request": { "urlPattern": "/sample-api", "method": "GET", "bodyPatterns" : [ { "matchesJsonPath" : "$..[?(@.cat == null || @.dog == null || @.horse == null || @.fish == null || @.id == null)]" } ] }, "response": { "status": "400", "headers": { "Content-Type": "application/json; " }, "jsonBody": { "message": "some sapi message" } } } |
CopyRight 2018-2019 实验室设备网 版权所有 |